/**
 * @Description
 * @Author LZL
 * @Date 2025/2/25
 */


package com.kcb.choose;

import com.kcb.coursemanager.*;
import javax.swing.*;
import java.awt.*;

public class choose2 extends JFrame {
    private JButton addCourseButton, deleteCourseButton, modifyCourseButton, inquireCourseButton, printCourseButton, exitButton, backButton;
    private String username;

    public choose2(String username) {
        this.username = username;
        setTitle("城科课程表管理系统:课程表管理");
        setSize(450, 400);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);

        ImageIcon icon = new ImageIcon("C:\\Users\\TBS\\IdeaProjects\\KCB\\image\\ccst.png");
        if (icon != null) {
            setIconImage(icon.getImage());
        } else {
            System.out.println("Failed to load icon image.");
        }


        // 主面板
        JPanel panel = new JPanel();
        panel.setBackground(new Color(240, 245, 255));
        panel.setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = new Insets(10, 10, 10, 10);
        gbc.fill = GridBagConstraints.HORIZONTAL;

        JLabel titleLabel = new JLabel("课程管理系统");
        titleLabel.setFont(new Font("宋体", Font.BOLD, 22));
        titleLabel.setForeground(new Color(50, 50, 150));

        // 按钮样式
        addCourseButton = createStyledButton("添加课程", new Color(60, 160, 250));
        deleteCourseButton = createStyledButton("删除课程", new Color(255, 120, 120));
        modifyCourseButton = createStyledButton("修改课程", new Color(255, 200, 0));
        inquireCourseButton = createStyledButton("查询课程", new Color(60, 200, 120));
        printCourseButton = createStyledButton("打印课程", new Color(140, 90, 200));
        exitButton = createStyledButton("退出系统", new Color(220, 80, 80));
        backButton = createStyledButton("返回", new Color(120, 120, 120));

        // 布局
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.gridwidth = 2;
        gbc.anchor = GridBagConstraints.CENTER;
        panel.add(titleLabel, gbc);

        gbc.gridy = 1; panel.add(addCourseButton, gbc);
        gbc.gridy = 2; panel.add(deleteCourseButton, gbc);
        gbc.gridy = 3; panel.add(modifyCourseButton, gbc);
        gbc.gridy = 4; panel.add(inquireCourseButton, gbc);
        gbc.gridy = 5; panel.add(printCourseButton, gbc);

        gbc.gridy = 6;
        gbc.gridwidth = 1;
        panel.add(backButton, gbc);

        gbc.gridx = 1;
        panel.add(exitButton, gbc);

        getContentPane().add(panel);

        // 按钮监听
        addCourseButton.addActionListener(e -> new addcourse(username).setVisible(true));
        deleteCourseButton.addActionListener(e -> new delcourse(username).setVisible(true));
        modifyCourseButton.addActionListener(e -> new modifycourse(username).setVisible(true));
        inquireCourseButton.addActionListener(e -> new inquirecourse(username).setVisible(true));
        printCourseButton.addActionListener(e -> new printcourse(username).setVisible(true));

        backButton.addActionListener(e -> {
            new choose(username).setVisible(true);
            dispose();
        });

        exitButton.addActionListener(e -> {
            int confirm = JOptionPane.showConfirmDialog(null, "确定要退出系统吗？", "确认退出", JOptionPane.YES_NO_OPTION);
            if (confirm == JOptionPane.YES_OPTION) {
                System.exit(0);
            }
        });
    }

    private JButton createStyledButton(String text, Color bgColor) {
        JButton button = new JButton(text);
        button.setFont(new Font("宋体", Font.BOLD, 16));
        button.setBackground(bgColor);
        button.setForeground(Color.WHITE);
        button.setFocusPainted(false);
        button.setBorderPainted(false);
        button.setPreferredSize(new Dimension(180, 45));
        return button;
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> new choose2("exampleUser").setVisible(true));
    }
}
